/**
  * Created by Joshua Conero(O'Uymas) on 2016/12/8 0008.
  * QQ: 957376074
  * E-mail: Brximl@163.com
  * GUI 主界面
  */
import java.io.File
import scala.swing.Swing._
import scala.swing.TabbedPane.Page
import scala.swing._
import scala.swing.event.ButtonClicked
class home(tab:TabbedPane,helper: Common) {
  // 文件编辑框
  val fileCreater = new TextArea(){
    columns = 400
    rows = 100
    preferredSize = new Dimension(550,400)
    border = Swing.EmptyBorder(5,5,5,5)
  }
  val fcPane = new ScrollPane(){
    contents = fileCreater
    preferredSize = new Dimension(400,300)
    border = Swing.EmptyBorder(5,5,5,5)
  }

  // 主页
  val mainPage = new FlowPanel{
    val fileChooser = new FileChooser(new File(".")){
      title = "打开文件"
    }
    val file_btn = new Button("打开文件")
    val new_btn = new Button("新建文件")
    contents += new_btn
    contents += file_btn
    listenTo(new_btn,file_btn)
    reactions += {
      case ButtonClicked(`new_btn`) =>
        this.contents += new BoxPanel(Orientation.Horizontal){
          border = CompoundBorder(TitledBorder(EtchedBorder, "新建爬虫规则"), EmptyBorder(5,100,20,300))
          val save_btn = new Button("保存")
          val run_btn = new Button("执行")
          val close_btn = new Button("关闭")
          contents += fcPane
          // 按钮组
          contents += new BoxPanel(Orientation.Horizontal){
            contents += run_btn
            contents += save_btn
            contents += close_btn
            contents += close_btn
            listenTo(save_btn,run_btn,close_btn)
            reactions += {
              case ButtonClicked(`save_btn`) =>
                val text = fileCreater.text
                //helper.put_content("/runtime/test.xml",text)
              case ButtonClicked(`run_btn`) =>
                val text = fileCreater.text
                println(text)
              case ButtonClicked(`close_btn`) =>
                println(8*0.14)
            }
            visible = true
          }
          visible = true
        }
        println(8)
      case ButtonClicked(`file_btn`) =>
        val fc = fileChooser.showDialog(this,"确定")
        println(fc)
    }
  }
  val leftMenu = new FlowPanel{
    contents += new Label("crawler")
  }
  tab.pages += new Page("crawler",new SplitPane(Orientation.Vertical,leftMenu,mainPage){
    continuousLayout = true
  })
}
